<?php

namespace app\common\dao\system\notice;


use app\common\dao\BaseDao;
use app\common\model\system\notice\SystemAppNoticeConfig;

class SystemAppNoticeConfigDao extends BaseDao
{

    protected function getModel(): string
    {
        return SystemAppNoticeConfig::class;
    }


    public function getNoticeStatusByKey(string $key, string $field)
    {
        $value = $this->getModel()::getDb()->where('notice_key',$key)->value($field);
        return $value == 1  ? true  : false;
    }



    public function search($where)
    {
        $query = $this->getModel()::getDb()
            ->when(isset($where['is_sms']) && $where['is_sms'] != '', function($query){
                $query->whereIn('notice_sms',[0,1]);
            })
            ->when(isset($where['is_routine']) && $where['is_routine'] != '', function($query){
                $query->whereIn('notice_routine',[0,1]);
            })
            ->when(isset($where['is_wechat']) && $where['is_wechat'] != '', function($query){
                $query->whereIn('notice_wechat',[0,1]);
            })
        ;
        return $query;
    }
}
